/*
 * nrf24l01.h
 *
 *  Created on: Oct 16, 2013
 *      Author: IEUser
 */

#ifndef NRF24L01_H_
#define NRF24L01_H_

/******************************************************************************************
 *	Deklaracje dołączanych plików nagłówkowych i bibliotek								 *
 *****************************************************************************************/
#include <avr/io.h>

#include "spi.h"
/******************************************************************************************
 *	Makrodefinicje															 			 *
 *****************************************************************************************/
#define NRF24L01_DDR	DDRB
#define NRF24L01_PORT	PORTB
#define NRF24L01_CE		PB1
#define NRF24L01_CSN	PB2

#define NRF24L01_CSN_LOW	NRF24L01_PORT &= ~(1<<NRF24L01_CSN)
#define NRF24L01_CSN_HIGH	NRF24L01_PORT |= (1<<NRF24L01_CSN)
#define NRF24L01_CE_LOW		NRF24L01_PORT &= ~(1<<NRF24L01_CE)
#define NRF24L01_CE_HIGH	NRF24L01_PORT |= (1<<NRF24L01_CE)

#define TX_MODE			1
#define RX_MODE			2
#define STANDBY_MODE	3
#define CHANNEL			1
#define	PAYLOAD			16

#define CONFIG		0x00
	#define MASK_RX_DR	6
	#define MASK_TX_DS	5
	#define MASK_MAX_RT	4
	#define EN_CRC		3
	#define CRCO		2
	#define PWR_UP		1
	#define PRIM_RX		0
#define EN_AA		0x01
	#define ENAA_P5		32
	#define ENAA_P4		16
	#define ENAA_P3		8
	#define ENAA_P2		4
	#define ENAA_P1		2
	#define ENAA_P0		1
#define EN_RXADDR	0x02
	#define ERX_P5		32
	#define ERX_P4		16
	#define ERX_P3		8
	#define ERX_P2		4
	#define ERX_P1		2
	#define ERX_P0		1
#define SETUP_AW	0x03
	#define AW_1		2
	#define AW_0		1
#define SETUP_RETR	0x04
	#define ARD_3		128
	#define ARD_2		64
	#define ARD_1		32
	#define ARD_0		16
	#define ARC_3		8
	#define ARC_2		4
	#define ARC_1		2
	#define ARC_0		1
#define RF_CH		0x05
	#define RF_CH_6		64
	#define RF_CH_5		32
	#define RF_CH_4		16
	#define RF_CH_3		8
	#define RF_CH_2		4
	#define RF_CH_1		2
	#define RF_CH_0		1
#define RF_SETUP	0x06
	#define PLL_LOCK	16
	#define RF_DR_MASK	3
		#define RF_DR_1M	0
		#define RF_DR_2M	1
	#define RF_PWR_MASK	0x01
		#define RF_PWR_18	0
		#define RF_PWR_12	1
		#define RF_PWR_6	2
		#define RF_PWR_0	3
	#define LNA_HCURR_MASK	0
		#define LNA_HCURR_O	0
		#define LNA_HCURR_1	0
#define STATUS		0x07
	#define RX_DR		6
	#define TX_DS		5
	#define MAX_RT		4
	#define RX_P_NO_2	3
	#define RX_P_NO_1	2
	#define RX_P_NO_0	1
	#define TX_FULL		0
#define OBSERVE_TX	0x08
#define CD			0x09
#define RX_ADDR_P0	0x0A
#define RX_ADDR_P1	0x0B
#define RX_ADDR_P2	0x0C
#define RX_ADDR_P3	0x0D
#define RX_ADDR_P4	0x0E
#define RX_ADDR_P5	0x0F
#define TX_ADDR		0x10
#define RX_PW_P0	0x11
#define RX_PW_P1	0x12
#define RX_PW_P2	0x13
#define RX_PW_P3	0x14
#define RX_PW_P4	0x15
#define RX_PW_P5	0x16
#define FIFO_STATUS	0x17
	#define	RX_EMPTY	0
#define DYNPD		0x1C
#define FEATURE		0x1D



#define R_REGISTER		0x1F
#define W_REGISTER		0x3F
#define R_RX_PAYLOAD	0x61
#define W_TX_PAYLOAD	0xA0
#define FLUSH_TX		0xE1
#define FLUSH_RX		0xE2
#define NOP				0xFF

/******************************************************************************************
 *	Deklaracje zmiennych pomocniczych i globalnych										 *
 *****************************************************************************************/

/******************************************************************************************
 *	Deklaracje funkcji								 									 *
 *****************************************************************************************/
void nrf24l01_init(void);
void nrf24l01_read_register(uint8_t reg, uint8_t *data_out, uint8_t lenght);
void nrf24l01_write_register(uint8_t reg, uint8_t byte);
void nrf24l01_config(uint8_t mode);
void nrf24l01_send(char *data);
void nrf24l01_flush_fifo(uint8_t mode);
uint8_t nrf24l01_data_ready(void);
void nrf24l01_get_data(char *data);

#endif /* NRF24L01_H_ */
